package com.caldremch.androidfoundation;

import android.app.Activity;
import android.app.Application;

import com.caldremch.androidfoundation.di.DaggerAppComponent;
import com.caldremch.androidfoundation.http.XHttp;
import com.caldremch.androidfoundation.utils.MyHttpUtils;
import com.squareup.leakcanary.LeakCanary;

import javax.inject.Inject;

import androidx.fragment.app.Fragment;
import dagger.android.AndroidInjector;
import dagger.android.DispatchingAndroidInjector;
import dagger.android.HasActivityInjector;
import dagger.android.support.HasSupportFragmentInjector;


/**
 *
 * @author Caldremch
 * @date 2018/11/3
 * @Email caldremch@163.com
 * @describe app
 *
 **/
public class App extends Application implements HasSupportFragmentInjector, HasActivityInjector {

    @Inject
    DispatchingAndroidInjector<Activity> mDispatchingAndroidInjector;

    @Inject
    DispatchingAndroidInjector<Fragment> mDispatchingAndroidInjectorSupportFragment;

    @Override
    public void onCreate() {
        super.onCreate();
        DaggerAppComponent.create().inject(this);
        XHttp.init(this);
        MyHttpUtils.init(this);
        initLeakCanary();
    }

    private void initLeakCanary() {

        if (LeakCanary.isInAnalyzerProcess(this)) {
            return;
        }

        LeakCanary.install(this);
    }

    @Override
    public AndroidInjector<Activity> activityInjector() {
        return mDispatchingAndroidInjector;
    }

    @Override
    public AndroidInjector<Fragment> supportFragmentInjector() {
        return mDispatchingAndroidInjectorSupportFragment;
    }
}
